# Maintainer: Giancarlo Razzolini <grazzolini@archlinux.org>
# Contributor: Timothy Redaelli <timothy.redaelli@gmail.com>
# Contributor: Kirill "reflexing" Churin <reflexing@reflexing.ru>
# Contributor: Andrej Gelenberg <andrej.gelenberg@udo.edu>

pkgname=keepass
pkgver=2.54
pkgrel=2
pkgdesc='Easy-to-use password manager for Windows, Linux, Mac OS X and mobile devices'
arch=('any')
url='https://keepass.info/'
license=('GPL')
depends=('mono' 'desktop-file-utils' 'xdg-utils' 'shared-mime-info' 'gtk-update-icon-cache')
makedepends=('icoutils')
optdepends=('argon2: For faster Argon2d and Argon2id'
            'libgcrypt: For faster AES-KDF'
            'xdotool: if you want to use auto-type'
            'xsel: clipboard operations in order to work around Mono clipboard bugs')
install="$pkgname.install"
source=("https://downloads.sourceforge.net/keepass/KeePass-$pkgver-Source.zip"
        "https://keepass.info/integrity/v2/KeePass-$pkgver-Source.zip.asc"
        'keepass'
        'keepass.1'
        'keepass.desktop'
        'keepass.xml')

md5sums=('e433703f94a39af28bb0894098332b3d'
         'SKIP'
         '628e383dbfcaeefa996e4677dca35ff1'
         'a2a0dff1ebf0aaf6cbfb6f8566f4a010'
         'e910fabacfd7a5f7caa7c1fac0b5254e'
         'cc97882563fbaa0d5db44c9089990f12')
sha1sums=('511cb9fb733f7ea2529b803e36098656cec324e2'
          'SKIP'
          '3142e80316feb67d687da993b919a634e89e6b1b'
          '9dadd198ff3c66a21f7df4192f5516556f6cfbd5'
          '22fab942358986679549e5263e1d4dabd23085f5'
          '6c7b7884bfb27d36d62fbd99df4ebc3004361df4')
sha256sums=('7c35d3e17c6825f3d5f2d53cb8bf786e72ffff32a5bd7192f44ccd96ce769098'
            'SKIP'
            '05e63a028198ff32d4b26a892923a821066541f0cf798f5be8c138739bc22fbe'
            'a5fff678466443c0c8256c4771128c86103da47b6a2c49351d9941191b65dd6f'
            '1d5420e8babce5f4bbb3c68bdffe3bc0d3c3be25ad689138cd02fa14edd89140'
            '3d017c17a8788166c644e2460ba3596fd503f300342561921201fe5f69e5d194')
validpgpkeys=('D95044283EE948D911E8B606A4F762DC58C6F98E')

prepare() {
  # Extract icons
  icotool -x KeePass/KeePass.ico

  pushd Build &>/dev/null
  LANG=en_US.UTF-8 bash PrepMonoDev.sh
  popd &>/dev/null
}

build() {
  xbuild /target:KeePass /property:Configuration=Release
  cp Ext/KeePass.exe.config Build/KeePass/Release/
}

package() {
  install -dm755 "$pkgdir"/usr/bin
  install -dm755 "$pkgdir"/usr/share/keepass/XSL

  install -Dm755 keepass "$pkgdir"/usr/bin/keepass
  install -Dm755 Build/KeePass/Release/KeePass.exe "$pkgdir"/usr/share/keepass/KeePass.exe
  install -Dm755 Ext/KeePass.config.xml "$pkgdir"/usr/share/keepass/KeePass.config.xml
  install -Dm755 Ext/KeePass.exe.config "$pkgdir"/usr/share/keepass/KeePass.exe.config

  install -m644 Ext/XSL/* "$pkgdir"/usr/share/keepass/XSL

  install -Dm644 keepass.1 "$pkgdir"/usr/share/man/man1/keepass.1

  # Proper installation of .desktop file
  desktop-file-install -m 644 --dir "$pkgdir"/usr/share/applications/ keepass.desktop

  # Install icons
  for size in 16 32 48 256; do
    install -Dm644 \
    KeePass_*_${size}x${size}x32.png \
    "$pkgdir"/usr/share/icons/hicolor/${size}x${size}/apps/keepass.png
  done

  # Needed for postinst with xdg-utils
  install -Dm644 keepass.xml "$pkgdir"/usr/share/mime/packages/keepass.xml
}
